// pages/wode/order/order.js
const http = require('../../../utils/http.js')
import regeneratorRuntime from '../../../utils/runtime.js'
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    var that = this;
    var res = await http.get('/carpool/get', {
      id: options.id
    });
    this.setData({
      info: res.result
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // /* 建议放在onReady里执行，提前加载广告 */
    // let InterstitialAd = qq.createInterstitialAd({ adUnitId: '82eb9ab75a718a0c85105253093f08e1' });
    // InterstitialAd.load().catch((err) => { console.error('load', err) })
    // InterstitialAd.onLoad(() => { console.log('onLoad event emit') })
    // InterstitialAd.onClose(() => { console.log('close event emit') })
    // InterstitialAd.onError((e) => { console.log('error', e) })
    // /* 建议放在需要展示插屏广告的时机执行 */
    // // InterstitialAd.show().catch((err) => { console.error('show', err) })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let appbox = qq.createAppBox({
      adUnitId: "be9d2747455d22566ad13e169013c68c"
    })
    appbox.load().then(() => {
      appbox.show()
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this.data;
    var msg = '';
    if (that.info.type == 1) {
      msg = '车找人，' + that.info.leaveAddress + '→' + that.info.arriveAddress + '，还有' + that.info.person + '个空位，快来联系我吧~'
    } else {
      msg = '人找车，' + that.info.leaveAddress + '→' + that.info.arriveAddress + '，我需要' + that.info.person + '个空位，快来联系我吧~'
    }
    console.log(msg);
    return {
      title: msg,
      path: '/pages/publish/order/order?id=' + that.info.id,
      imageUrl: '../../../image/share.jpg'
    }
  },
  call: function (e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone,
    })
  },
  copy: function (e) {
    qq.setClipboardData({
      data: e.currentTarget.dataset.phone,
      success(res) {
        qq.showModal({
          title: '提示',
          content: '复制手机号成功',
          showCancel: false,
        })
      }
    })
  },
  go: function () {
    wx.switchTab({
      url: '/pages/home/index',
    })
  }
})